package ast.stmt;

import icg.EQLabel;
import ts.SymbolTable;
import ast.type.Type;

public class SeqStmt extends Statement {
	private Statement s1;
	private Statement s2;

	public SeqStmt(Statement s1, Statement s2) {
		this.s1 = s1;
		this.s2 = s2;
	}

	@Override
	public String toString() {
		return s1 + "\n" + s2;
	}

	@Override
	public void typeCheck(Type type) {
		s1.typeCheck(type);
		s2.typeCheck(type);
	}

	@Override
	public Boolean isReturned() {
		if (s1.isReturned()) {
			System.out.println("unreachable statement");
			SymbolTable.errors++;
		}
		return s2.isReturned();
	}

	public Boolean hasCtrlFlow() {
		return (s1.hasCtrlFlow() || s2.hasCtrlFlow());
	}

	@Override
	public void genCode() {
		s1.next = EQLabel.FALL;
		s2.next = this.next;
		s1.genCode();
		s2.genCode();
	}
}
